/**
 * @description sequelize 配置
 * @author chengpeng
 */
const Sequelize = require('sequelize')
const {
    MYSQL_CONFIG
} = require('../config/db')
const {
    isProd,
    isTest
} = require('../utils/env')

// sql配置
const {
    host,
    user,
    password,
    database
} = MYSQL_CONFIG
const config = {
    host,
    dialect: 'mysql'
}

// 单元测试关闭seq语句
if (isTest) {
    config.logging = () => {}
}

// 线上连接池
if (isProd) {
    config.pool = {
        max: 5,
        min: 0,
        idle: 10000 // 10s内未被使用释放
    }
}

const seq = new Sequelize(database, user, password, config)

module.exports = seq